package com.atguigu.gulimall.redisson;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author nicc
 * @version 1.0
 * @className RedissonConfiguration
 * @date 2022-10-08 14:45
 */
@Configuration
public class RedissonConfiguration {

    @Autowired
    RedisProperties redisProperties;

    @Bean
    public RedissonClient redissonClient(){
        Config config = new Config();
        config.useSingleServer()
                .setAddress("redis://"+redisProperties.getHost()+":"+redisProperties.getPort())
                .setPassword(redisProperties.getPassword());
        //自行修改默认的看门狗时间
//        config.setLockWatchdogTimeout()
        //1、创建redisson客户端
        RedissonClient redisson = Redisson.create(config);
        return redisson;
    }


    /**
     * 具体初始化布隆过滤器交给需要使用的服务进行各自的初始化
     */
//    @Bean
//    public RBloomFilter<Object> skuIdBloom(){
//        RedissonClient client = redissonClient();
//        RBloomFilter<Object> skuIdBloom = client.getBloomFilter(RedisConst.BLOOM_SKUID);
//
//        if(!skuIdBloom.isExists()){
//            //初始化分布式布隆
//            skuIdBloom.tryInit(1000000, 0.0000001);
//
//            //拿到商品id
//        }
//        return skuIdBloom;
//    }
}
